{% extends "olexam/base.html" %}

{% block content %}
    <h2>考试列表</h2>
    <div class="list-group">
        {% for exam in exams %}
            <div class="list-group-item">
                <div class="d-flex justify-content-between">
                    <h5>{{ exam.title }}</h5>
                    <span class="badge bg-{% if exam.is_available %}success{% else %}secondary{% endif %}">
                        {{ exam.get_status_display }}
                    </span>
                </div>
                <p>{{ exam.description }}</p>
                <div class="d-flex justify-content-between">
                    <small>
                        时间: {{ exam.start_time|date:"Y-m-d H:i" }} 至 {{ exam.end_time|date:"Y-m-d H:i" }} |
                        时长: {{ exam.duration }}分钟 | 总分: {{ exam.total_score }}
                    </small>
                    <div>
                        {% if exam.user_attempt %}
                            <a href="{% url 'exam_result' exam.user_attempt.id %}" class="btn btn-sm btn-info">
                                查看结果
                            </a>
                        {% elif exam.is_available %}
                            <a href="{% url 'take_exam' exam.id %}" class="btn btn-sm btn-primary">
                                参加考试
                            </a>
                        {% endif %}
                    </div>
                </div>
            </div>
        {% empty %}
            <div class="alert alert-info">当前没有可用的考试</div>
        {% endfor %}
    </div>
{% endblock %}
